﻿using System.ServiceProcess;
using Quartz;
using Quartz.Impl;
using System;
using Quartz.Xml;
using Quartz.Simpl;
using Jsptpd.Common.quartzHelper;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Configuration;
using System.IO;

namespace Jsptpd.JobScheduler
{
    public partial class jsptpdJobScheduler : ServiceBase
    {
        private readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(jsptpdJobScheduler));
        private IScheduler scheduler;       
        public jsptpdJobScheduler()
        {
            InitializeComponent();            
            logger.Info("Initial complete");
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            scheduler = schedulerFactory.GetScheduler();
        }

        protected override void OnStart(string[] args)
        {
            JobHelper jh = new JobHelper();
            //cronexpression:Monday-Friday 01:00 fire,the string is:"0 0 1 * * MON-FRI"
            jh.fireInSpecifyTime(scheduler, "0 */1 * * * ?");
            logger.Info("Quartz service start success...");            
        }

        protected override void OnStop()
        {
            scheduler.Shutdown();
            logger.Info("Quartz service stop success...");
        }

        protected override void OnPause()
        {
            scheduler.PauseAll();
        }

        protected override void OnContinue()
        {
            scheduler.ResumeAll();
        }
    }
}
